<template>
    <div class="">
        <div class="pr10">
            <div class="analyItem">
                <p class="analyItemTit tx-center">状态</p>
                <div class="analyItemCon">

                </div>
            </div>
        </div>
        <div class="thinScroll pr10" v-scrollHeight="84">
            <div class="analyItem">
                <p class="analyItemTit tx-center">结果</p>
                <div class="analyItemCon">
                    <p class="col-md-6">
                        <span class="cLightGray pr8">竣工单数</span>
                        <span>{{resultList.length}}</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">工期超期项目</span>
                        <span>{{count}}</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">过程</p>
                <div class="analyItemCon">
                            <p class="col-md-6">
                        <span class="cLightGray pr8">在施单数</span>
                        <span>{{processList.length}}</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">评价完成率</span>
                        <span></span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">管理</p>
                <div class="analyItemCon">
                          <p class="col-md-6">
                        <span class="cLightGray pr8">状态</span>
                        <span></span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">时间</span>
                        <span></span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">人事</p>
                <div class="analyItemCon">
                            <p class="col-md-6">
                        <span class="cLightGray pr8">入职时间</span>
                        <span>{{course.inductionDate}}</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">登录时间</span>
                        <span>{{time}}</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">资金</p>
                <div class="analyItemCon">
                           <p class="col-md-6">
                        <span class="cLightGray pr8">产值</span>
                        <span>{{capital.outputType}}</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">待回款</span>
                        <span>{{processDCount |toFixed(2)}}</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">积分</p>
                <div class="analyItemCon">
                          <p class="col-md-6">
                        <span class="cLightGray pr8">分数</span>
                        <span>{{60-IntegralHandle.cur_stage}}</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">状态</span>
                            <span class="cGreen" v-if="IntegralHandle.cur_stage ===0" >正常</span>
                        <span class="cOrange" v-else-if="IntegralHandle.cur_stage ===1" >异常</span>
                        <span style="color: #FF9900" v-else-if="IntegralHandle.cur_stage ===2" >问题</span>
                        <span class="cRed" v-else-if="IntegralHandle.cur_stage ===3" >整改</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">成就</p>
                <div class="analyItemCon">
                            <p class="col-md-6">
                        <span class="cLightGray pr8">竣工额</span>
                        <span>{{Amount.grossProfitReceived===undefined?0:(Amount.grossProfitReceived/10000).toFixed(2)}}万</span>
                    </p>
                        <p class="col-md-6">
                        <span class="cLightGray pr8">培训次数</span>
                        <span>{{Amount.trainNum===undefined?0:Amount.trainNum}}</span>
                    </p>
                </div>
            </div>
        </div>
        <div class="pr10">
            <router-link tag="div" :to="routerPath('hander')" class="analyItem anItemBor" active-class="anItemBor-active">
                <p class="analyItemTit tx-center">处理</p>
                <div class="analyItemCon">
                </div>
            </router-link>
        </div>
    </div>
</template>
<script>
import {
    mapGetters
} from 'vuex'
import {fingCurStage, countAchievementHistoryMoney,
    GetByuidProjectManagerProcess, findMeCourse,
    GetAppLastLoginTime, GetByuidProjectManagerResult
    , selectAllCityAndCompany, GetByUIdFundInformation, getPmUserinfoProjectProcessbyUid, getConstructionTimeByOrderNo
} from '../Resources/Api'
export default {
    data () {
        return {
            IntegralHandle: {},
            Amount: {},
            processList: [],
            course: {},
            time: '',
            resultList: [],
            capital: {},
            region: '',
            processMoney: [],
            count: 0

        }
    },
    created () {
        this.GetCurStage()
        this.HisDeposit()
        this.getProjectManagerProcess()
        this.findCourse()
        this.GetAppLastLoginTimeFn()
        this.GetProjectManagerResult()
        this.selectAllCityAndCompanyFn()
        this.GetByuidProjectManagerResult()
    },
    methods: {
    // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        // 查询指定人员资金板块奖罚数据
        GetByUIdFundInformationFn () {
            let _this = this
            _this.capital = {}
            GetByUIdFundInformation({
                uid: _this.leftInfo.uid,
                area: _this.region
            }).then(results => {
                _this.capital = results.data.Body
            }).catch(error => {
                console.log(error)
            })
        },
        // 通过分司ID去除相同等级地区
        selectAllCityAndCompanyFn () {
            let _this = this
            _this.region = ''
            selectAllCityAndCompany({
                companyId: _this.leftInfo.dq_id
            }).then(results => {
                for (let i = 0; i < results.data.length; i++) {
                    _this.region = _this.region + results.data[i].cpId + ','
                }
                _this.region = _this.region.substr(0, _this.region.length - 1)
                _this.GetByUIdFundInformationFn()
            }).catch(error => {
                console.log(error)
            })
        },
        PmUserinfoProjectProcessbyUid () {
            let _this = this
            _this.processMoney = []
            getPmUserinfoProjectProcessbyUid({
                uid: this.leftInfo.uid
            }).then(result => {
                if (result.data.StatusCode !== 100) {
                    _this.processMoney = result.data.Body
                } else {
                    _this.processMoney = []
                }
            }).catch(err => {
                console.log(err)
            })
        },
        GetConstructionTime (value) {
            let _this = this
            _this.constructionTime = {}
            getConstructionTimeByOrderNo({
                orderNo: value
            }).then(results => {
                if (results.data.Body) {
                    _this.constructionTime = results.data.Body
                    if (_this.constructionTime.surplusDays < 0) {
                        this.count++
                    }
                } else {
                    _this.constructionTime = {
                        constructionPeriod: 0,
                        constructionTime: '',
                        constructionDelay: 0,
                        surplusDays: 0
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        GetProjectManagerResult () {
            let _this = this
            _this.resultList = []
            this.count = 0
            GetByuidProjectManagerResult({
                uid: _this.leftInfo.uid
            })
                .then(results => {
                    _this.resultList = results.data.Body
                    _this.resultList.forEach(element => {
                        let orderId = element.orderNo
                        this.GetConstructionTime(orderId)
                    })
                })
                .catch(error => {
                    console.log(error)
                })
        },

        // 查询最近登陆时间
        GetAppLastLoginTimeFn () {
            let _this = this
            _this.time = ''
            GetAppLastLoginTime({
                CardNo: this.leftInfo.app_cardNo,
                AppId: this.leftInfo.rs_app_id
            }).then(results => {
                if (results.data.StatusCode === 0) {
                    _this.time = results.data.Body.replace('/', '-')
                    _this.time = _this.time.replace('/', '-')
                } else {
                    _this.time = ''
                }
            }).catch(error => {
                console.log(error)
            })
        },
        GetCurStage () {
            let _this = this
            _this.IntegralHandle = {}
            fingCurStage({
                uid: _this.leftInfo.uid
            }).then(results => {
                _this.IntegralHandle = results.data.Body
                if (_this.rejectUser == null) {
                    _this.rejectUser = {}
                }
            }).catch(error => {
                console.log(error)
            })
        },
        findCourse () {
            let _this = this
            _this.course = {}
            findMeCourse({
                uid: this.leftInfo.uid,
                appCard: this.leftInfo.app_cardNo
            }).then(results => {
                _this.course = results.data.Body
            }).catch(err => {
                console.log(err)
            })
        },
        HisDeposit () {
            let _this = this
            _this.Amount = {}
            countAchievementHistoryMoney({
                uid: this.leftInfo.uid
            }).then(result => {
                this.Amount = result.data.Body
            }).catch(error => {
                console.log(error)
            })
        },
        getProjectManagerProcess () {
            let _this = this
            _this.processList = []
            GetByuidProjectManagerProcess({
                uid: _this.leftInfo.uid
            }).then(results => {
                _this.processList = results.data.Body
            }).catch(error => {
                console.log(error)
            })
        }
    },
    computed: {
        ...mapGetters(['leftInfo']),
        processDCount () {
            if (this.processMoney.length > 0) {
                return this.processMoney.map(startReady => startReady.returnMoney).reduce((acc, cur) => (parseFloat(cur) + acc), 0)
            } else {
                return 0
            }
        }
    },
    watch: {
        leftInfo () {
            this.GetCurStage()
            this.HisDeposit()
            this.getProjectManagerProcess()
            this.findCourse()
            this.GetAppLastLoginTimeFn()
            this.GetProjectManagerResult()
            this.selectAllCityAndCompanyFn()
        }
        // $route () {
        //     this.change()
        // }
    }
}
</script>
